<template>
  <el-dialog :visible.sync="visible" title="" width="420px" @close="onClose" class="custom-dialog">
    <div class="dialog-title">注册</div>
    <el-form :model="form" ref="registerForm" label-width="0" class="custom-form">
      <el-form-item>
        <el-input v-model="form.username" autocomplete="off" class="custom-input" placeholder="用户名" />
      </el-form-item>
      <el-form-item>
        <el-input v-model="form.password" type="password" autocomplete="off" class="custom-input" placeholder="密码" />
      </el-form-item>
      <el-form-item>
        <el-input v-model="form.confirmPassword" type="password" autocomplete="off" class="custom-input" placeholder="确认密码" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="onClose" class="custom-btn">取消</el-button>
      <el-button type="primary" @click="onRegister" class="custom-btn primary-btn">注册</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'RegisterDialog',
  props: {
    visible: Boolean
  },
  data() {
    return {
      form: {
        username: '',
        password: '',
        confirmPassword: ''
      }
    }
  },
  methods: {
    onRegister() {
      if (!this.form.username || !this.form.password) {
        this.$message.error('请输入用户名和密码');
        return;
      }
      if (this.form.password !== this.form.confirmPassword) {
        this.$message.error('两次输入的密码不一致');
        return;
      }
      // 保存到localStorage
      localStorage.setItem('user', JSON.stringify({
        username: this.form.username,
        password: this.form.password
      }));
      this.$emit('register-success', {
        username: this.form.username
      });
      this.onClose();
    },
    onClose() {
      this.$emit('update:visible', false);
    }
  }
}
</script>

<style scoped>
.custom-dialog >>> .el-dialog {
  border-radius: 18px;
  box-shadow: 0 10px 40px rgba(64,158,255,0.13), 0 2px 8px rgba(0,0,0,0.08);
  background: #fff;
  padding-bottom: 0;
  font-size: 12px;
}
.dialog-title {
  text-align: center;
  font-size: 22px;
  font-weight: 800;
  color: #222;
  margin-bottom: 32px;
  letter-spacing: 1px;
  margin-top: 8px;
}
.custom-form {
  margin-bottom: 0;
  font-size: 12px;
}
.custom-input {
  display: flex;
  justify-content: center;
}
.custom-input >>> .el-input__inner {
  width: 240px;
  margin: 0 auto;
  border-radius: 10px;
  height: 36px;
  font-size: 12px;
  padding-left: 10px;
}
.el-form-item {
  margin-bottom: 20px;
  font-size: 12px;
}
.el-form-item__label {
  font-size: 12px !important;
}
.dialog-footer {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 0;
  padding-bottom: 8px;
}
.custom-btn {
  border-radius: 8px;
  min-width: 90px;
  height: 36px;
  font-size: 12px;
}
.primary-btn {
  width: 90px;
  background: #409eff;
  border-color: #409eff;
  color: #fff;
  font-weight: 600;
}
.primary-btn:hover {
  background: #66b1ff;
  border-color: #66b1ff;
}
:deep(.el-dialog__body) {
  padding: 0px 20px;
}
</style> 